//
//  KBaseResponedSearchCommandDTO.m
//  KutulusLaw
//
//  Created by Mahmood1 on 12/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "KBaseResponedSearchCommandDTO.h"

@implementation KBaseResponedSearchCommandDTO
@synthesize isOK = _isOK, total = _total, rows = _rows;

- (id)init {
    self = [super init];
    if (self) {
        self.isOK = FALSE;
        self.total = 0;
        self.rows = [[NSMutableArray alloc] init];
    }
    return self;
}

- (id)initWithDictionary:(NSDictionary *)dictionary {
    self = [self init];
    
    if (self) {
		NSLog(@"%@", [dictionary objectForKey:kKEY_STATUS]);
		if ([dictionary objectForKey:kKEY_STATUS] && [[dictionary objectForKey:kKEY_STATUS] isEqualToString:@"OK"] ) {
			self.isOK = TRUE;
		}
		
		if ([dictionary objectForKey:kKEY_TOTAL]) {
			self.total = [[dictionary objectForKey:kKEY_TOTAL] integerValue];
		}
		
		if ([dictionary objectForKey:kKEY_ROWS]) {
			self.rows = [[NSMutableArray alloc] init];
			
			NSDictionary *rowsDic = [dictionary objectForKey:kKEY_ROWS];
			
			for (NSDictionary *row in rowsDic) {
				KBaseSearchFileDTO *searchFileDTO = [self parseRow:row];
				
				[self.rows addObject:searchFileDTO];
			}
		}
		
    }
    
    return self;
}



- (KBaseSearchFileDTO *)parseRow:(NSDictionary *)row {
	KBaseSearchFileDTO *baseSearchFile = [[KBaseSearchFileDTO alloc] initWithDictionary:row];
	
	return baseSearchFile;
}

- (NSInteger) countOfRows {
	if (self.rows) {
		return [self.rows count];
	}
	
	return 0;
}

- (KBaseSearchFileDTO *) objectInRowsAtIndex:(NSUInteger)index {
	if (index < [self countOfRows]) {
		return [self.rows objectAtIndex:index];
	}
	
	return nil;
}
@end
